namespace Geekeradmin.Common
{
    public class WebsocketClientCollection
    {
        private static List<WebsocketClient> _clients = new List<WebsocketClient>();

        public static void UpdateTime(WebsocketClient client)
        {
            var haveadata = _clients.Where(o => o.RoomNo == client.RoomNo);
            if (haveadata.Count() > 0)
            {
                haveadata.FirstOrDefault().dateTime = DateTime.Now;
            }
        }

        public static void Add(WebsocketClient client)
        {
            _clients.Add(client);
        }

        public static void Remove(WebsocketClient client)
        {
            _clients.Remove(client);
        }

        public static void RemoveByToken(WebsocketClient client)
        {
            var havedata=_clients.Where(o=>o.RoomNo==client.RoomNo);
            if (havedata.Count() > 0)
            {
                _clients.Remove(havedata.FirstOrDefault());
            }

        }
        public static WebsocketClient Get(string clientId)
        {
            var client = _clients.FirstOrDefault(c => c.Id == clientId);
            return client;
        }

        public static List<WebsocketClient> GetRoomClients(string RoomNo)
        {
            var client = _clients.Where(c => c.RoomNo == RoomNo);
            return client.ToList();
        }
    }
}
